﻿
using Hotel.DAL;
using Hotel.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Hotle.BLL
{
    public class MemberBLL
    {
        public MemberBLL(MemberDAL dal)
        {
            Dal = dal;
        }

        public MemberDAL Dal { get; }

        /// <summary>
        /// 会员添加
        /// </summary>
        /// <returns></returns>
        public int MemberAdd(MemberModel member)
        {
            try
            {
                return Dal.MemberAdd(member);
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
        /// <summary>
        /// 逻辑删除
        /// </summary>
        /// <returns></returns>
        public int LDelet(int id)
        {
            try
            {
                return Dal.LDelet(id);

            }
            catch (Exception ex)
            {

                throw;
            }
        }

        /// <summary>
        /// 修改 修改(反填-id查询)
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public MemberModel UpMember(int id)
        {
            try
            {
                return Dal.FanTianMember(id);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// 修改 
        /// </summary>
        /// <returns></returns>
        public int Updata(MemberModel member)
        {
            try
            {
                return Dal.Updata(member);
            }
            catch (Exception ex)
            {

                throw ex;
            }

        }

        /// <summary>
        /// 会员添加
        /// </summary>
        /// <returns></returns>
        public int WYMemberAdd(string Phone, string Card)
        {
            try
            {
               return Dal.WYMemberAdd(Phone, Card);
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }

        /// <summary>
        /// 会员等级添加
        /// </summary>
        /// <returns></returns>
        public int LevelAdd(LevelModel level)
        {
            try
            {
                //1.等级
                var aa = Dal.IsLeveName(level.LName);
                if (aa > 0 )
                {
                    return -1;//表示重复
                }else
                {
                    var aa1 = Dal.LevelAdd(level);
                    return aa1;
                }
            }
            catch (Exception)
            {
                throw;
            }
        }


        /// <summary>
        /// 等级List
        /// </summary>
        /// <returns></returns>
        public List<LevelModel> LevelList()
        {
            return Dal.LevelList();
        }

        //
        public List<MemberModel> Memebrlist(int? id, string? name, int? levelId)
        {
            try
            {
                return Dal.Memebrlist(id, name, levelId);
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 权益添加
        /// </summary>
        /// <returns></returns>
        public int RightAdd(RightModel right)
        {
            return Dal.RightAdd(right);
        }

        /// <summary>
        /// 权益List
        /// </summary>
        /// <param name="totalConut"></param>
        /// <param name="topage"></param>
        /// <param name="name"></param>
        /// <param name="CTime"></param>
        /// <param name="ETime"></param>
        /// <param name="index"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        public List<RightModel> RightList(out int totalConut, out int topage, string? name, DateTime? CTime, DateTime? ETime, int index = 1, int size = 3)
        {
            return Dal.RightList(out totalConut, out topage, name, CTime, ETime, index, size);
           
        }


        //修改会员权益状态
        public int UpdateRightstate(int id, int state)
        {
            int info = Dal.UpdateRightstate(id, state);
            if (info > 0)
            {
                return 1;//修改成功
            }else
            {
                return -1;//修改失败
            }
        }


    }
}
